$("body").on('ifClicked', "input[name='isShow']", function () {
    var value = $(this).val();
    if (value == "2") {
        $("#showDetail").addClass("hide");
    } else {
        $("#showDetail").removeClass("hide");
    }
}).on('ifClicked', "input[name='showLocationTop']", function () {
    var value = $("input[name='showLocationTop']:checked").val();
    if (value == "1") {
        $("#showLocationTop").addClass("hide");
    } else {
        $("#showLocationTop").removeClass("hide");
    }
}).on('ifClicked', "input[name='showLocationTail']", function () {
    var value = $("input[name='showLocationTail']:checked").val();
    if (value == "1") {
        $("#showLocationTail").addClass("hide");
    } else {
        $("#showLocationTail").removeClass("hide");
    }
}).on("click", "#saveOverallAdvert", function () {
    saveOverallAdvert();
}).on("click", "#logoImgByTopButton", function () {
    logoImgByTop();
}).on("click", "#logoImgByTailButton", function () {
    logoImgByTail();
}).on("change", "#chainedTypeByTop", function () {
    var value = $(this).val();
    if (value != null && value != '0' && value != '') {
        $("#chainedByTop").removeClass("hide");
    } else {
        $("#chainedByTop").addClass("hide");
    }
}).on("change", "#chainedTypeByTail", function () {
    var value = $(this).val();
    if (value != null && value != '0' && value != '') {
        $("#chainedByTail").removeClass("hide");
    } else {
        $("#chainedByTail").addClass("hide");
    }
});

function logoImgByTop() {
    initUpdateFileWin({
        fileType: 'img',//文类类型["img","ico","xls","pdf","zip"]
        callback: 'uploadImgTopCallback',
        cut: false,//开启剪切
        imgSize: DEFAULT_CLASS_IMG_SIZE,//剪切上传后生成图片的规格（开启剪切才起使用）
        aspectRatio: 1 / 1//剪切区域的高宽比例（开启剪切才起使用）
    });
}

function logoImgByTail() {
    initUpdateFileWin({
        fileType: 'img',//文类类型["img","ico","xls","pdf","zip"]
        callback: 'uploadImgTailCallback',
        cut: false,//开启剪切
        imgSize: DEFAULT_CLASS_IMG_SIZE,//剪切上传后生成图片的规格（开启剪切才起使用）
        aspectRatio: 1 / 1//剪切区域的高宽比例（开启剪切才起使用）
    });
}

function uploadImgTopCallback(param) {
    $(".logoImgByTop").attr("src", param.url)
}

function uploadImgTailCallback(param) {
    $(".logoImgByTail").attr("src", param.url)
}

function saveOverallAdvert() {
    var params = dealWith();
    params = JSON.stringify(params);
    $.ajax({
        url: baseloaction + '/admin/planTools/overallAdvert/saveOverallAdvert',
        data: params,
        type: 'post',
        contentType: 'application/json;charset=utf-8',
        success: function (response) {
            icModale(0, response.message);
        }
    });
}


function dealWith() {
    var data = {};
    data.id = $("#overallAdvertInfoId").val();
    var attributeMap = {};
    attributeMap.isShow = $("input[name='isShow']:checked").val();
    attributeMap.showLocationTop = $("input[name='showLocationTop']:checked").val() != null ? $("input[name='showLocationTop']:checked").val() : 0;
    attributeMap.showLocationTail = $("input[name='showLocationTail']:checked").val() != null ? $("input[name='showLocationTail']:checked").val() : 0;
    attributeMap.isShow = $("input[name='isShow']:checked").val();
    attributeMap.isClosableByTop = $("input[name='isClosableByTop']:checked").val();
    attributeMap.isClosableByTail = $("input[name='isClosableByTail']:checked").val();
    attributeMap.logoImgByTop = $("#logoImgByTop").attr('src');
    attributeMap.logoImgByTail = $("#logoImgByTail").attr('src');
    attributeMap.chainedByTop = $("input[name='chainedByTop']").val();
    attributeMap.chainedByTail = $("input[name='chainedByTail']").val();
    attributeMap.chainedTypeByTop = $("#chainedTypeByTop option:selected").val();
    attributeMap.chainedTypeByTail = $("#chainedTypeByTail option:selected").val();
    data.attributeMap = attributeMap;
    return data;
}